/**
 * @projectDescription modules used in main.html
 * MUNS copyright, 2010
 * @author xkx
 */
//MUN.module.autocompleter
MUN.module.autocompleter = new Object();
MUN.module.autocompleter.create = function(id, items, upshow, placeholder)
	{
		var autocomleter =  new Autocompleter.Local(id, items , {
			'minLength': 1,
			'maxChoices': 6,
			'selectMode': 'type-ahead',
			'showTop': upshow,
			'injectChoice': MUN.util.autocomplete_setting
			});
		$(id).addEvent('focus',function(){MUN.module.autocompleter.remove_placeholder(id, placeholder)});
		$(id).addEvent('blur',function(){MUN.module.autocompleter.check_entry_placeholder(id, placeholder)});
		MUN.module.autocompleter.check_entry_placeholder(id, placeholder);
		return true;
	};
MUN.module.autocompleter.check_entry_placeholder = function(id, placeholder)
	{
		if($(id).value == "")
			{
				$(id).value = placeholder;
			}
	};
MUN.module.autocompleter.remove_placeholder = function(id, placeholder)
	{
		if($(id).value == placeholder)
		{$(id).value = "";}
	};

//MUN.module.board_box
MUN.module.board_box = new Object();
window.addEvent('domready', function(){
	MUN.module.board_box.board = $('board');
	MUN.module.board_box.scrollbar = false;
	});
MUN.module.board_box.create = function(id)
	{
		this.box_parent = new Element('div',{'class': '_box-area'}).inject($('board'));
		
		this.container = new Element('div',{'id': id, 'class': '_box'}).inject(this.box_parent);
		this.content = new Element('div',{'class': '_box-content'}).inject(this.container);
		this.header = new Element('h1',{'class': '_box-header'}).inject(this.content);
		this.tools = new Element('div',{'class': '_box-tools'}).inject(this.container);
		
		return true;
	};
MUN.module.board_box.toBottom = function()
	{
		if(!MUN.module.board_box.scrollbar)
		{
			var board = MUN.module.board_box.board;
			if(MUN.module.board_box.board.getScrollSize().y > MUN.module.board_box.board.getSize().y)
			{
				board.style.overflowY = 'scroll';
				board.style.overflowY;
				MUN.module.board_box.scroll = new Fx.Scroll('board');
				MUN.module.board_box.scrollbar = true;
				MUN.module.board_box.scroll.toBottom();
			}
		}
		else
		{
			MUN.module.board_box.scroll.toBottom();
		}
	};
//MUN.module.motion	
MUN.module.motion = 
{
	menu : new MUN.module.menu.create("motion-menu","_button-menu"),
	buttons : [],
	create : function(id)
	{
		var button =  new Element('button',
			{
				'text' : "Motion",
				'id' : id,
				'class' : "motion-button",
				'onclick' : "MUN.module.motion.motion('" + id +"');"
			});
		button.disabled = !MUN.status.motion_ok;
		this.buttons.push(button);
		return button;
	},
	enable : function()
	{
		for(var i = 0;i<this.buttons.length;i++)
		{
			this.buttons[i].disabled = false;
		}
	},
	disable : function()
	{
		for(var i = 0;i<this.buttons.length;i++)
		{
			this.buttons[i].disabled = true;
		}
	},
	hide : function()
	{
		this.menu.hide();
	},
	motion : function(id)
	{
		this.menu.show(id);
	},
	change_menu : function(msg)
	{
		switch (msg)
		{
			case 'out-of-rollcall': this.menu.add_items({"To Set Agenda":this.set_agenda});
		}
		
	},
	//specific motions
	set_agenda : function()
	{
		var motion_agenta_box = new MUN.module.board_box.create("motion-agenta-box");
		motion_agenta_box.header.innerText = 'Motion';
		MUN.module.board_box.toBottom();
		//resize_list();
		
	}
};
//MUN.module.submit
MUN.module.submit = 
{
	menu : new MUN.module.menu.create("submit-menu","_button-menu"),
	buttons : [],
	create : function(id)
	{
		var button =  new Element('button',
			{
				'text' : "Submit",
				'id' : id,
				'class' : "submit-button",
				'onclick' : "MUN.module.submit.submit('" + id +"');"
			});
		button.disabled = !MUN.status.submit_ok;
		this.buttons.push(button);
		return button;
	},
	enable : function()
	{
		for(var i = 0;i<this.buttons.length;i++)
		{
			this.buttons[i].disabled = false;
		}
	},
	disable : function()
	{
		for(var i = 0;i<this.buttons.length;i++)
		{
			this.buttons[i].disabled = true;
		}
	},
	hide : function()
	{
		this.menu.hide();
	},
	motion : function(id)
	{
		this.menu.show(id);
	},
	change_menu : function(msg)
	{
		
	},
	//specific submissions
};